<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>全一科技</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <link href="/home/css/forget.css" type="text/css" rel="stylesheet">
    <link href="/home/css/global.css" type="text/css" rel="stylesheet">
    <style type="text/css">

        body{
            overflow: hidden;
            background: url(../images/reg_bg.png) no-repeat;
            background-size: 100% 100%;
            -moz-background-size: 100% 100%;
            -webkit-background-size: 100% 100%;
        }
    </style>
</head>
<body>
<div style="position: relative;">
    <a href="#" onClick="javascript:history.back(-1);"><img src="/home/images/icon/re.png"  style="display: block;position: absolute;left: 2%; margin-top: 3%;"></a>
</div>
<div id="layout">
    <span>重置密码</span>
    <form action="/home/forget/changeindex" method="POST"  id="form4" onsubmit="return fn3()">
        {{csrf_field()}}
        <ul>
            <p id="err_msg"></p>
            <li><i class="un"><img src="/home/images/user_name.png"></i><input class="username" id="phone" name="phone" type="text" placeholder="请输入手机号" /></li>
            <li><i class="yz"><img src="/home/images/msg.png"></i><input class="yzm" style="width: 43.8%" id="yzm" type="text" name="yzm" placeholder="请输入手机验证码" /><input type="button" id="send" value="获取验证码"/></li>
        </ul>
        <div class="reg_btn">
            <button class="submit" type="button" id='btn'>下一步</button>
        </div>
    </form>
</div>
</body>
<script src="/home/js/jquery.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var err_msg = document.getElementById('err_msg');
    var phone = document.getElementById('phone');
    var yzm = document.getElementById('yzm');
    var send = document.getElementById('send');
    function phonefn() {
        if(phone.value == "") {
            err_msg.innerHTML = "*手机号不能为空";
            return false;
        }else{
            var regex = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
            if(regex.test(phone.value) == true) {
                err_msg.innerHTML = "";
                return true;
            } else {
                err_msg.innerHTML = "*手机格式输入不正确";
                return false;
            }
        }
    }
    phone.onblur = phonefn;


    times=60,
        timer=null;
    $('#send').click(function(){
        var tel = $.trim($('#phone').val());
        var regex = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        console.log(tel);
        // 计时开始
        timer = setInterval(djs,1000);
        $.post('/home/forget/code', {'mobile':tel,'_token':$('input[name=_token]').val()},function(num){

            if(num.status == 2) {
                document.getElementById('err_msg').innerHTML = "*该用户不存在";
                return false;
            }
            if (num) {
                if(regex.test(phone.value)) {
                    document.getElementById('err_msg').innerHTML = "*验证码发送成功"
                    return true;
                } else {
                    err_msg.innerHTML = "手机号格式输入不正确";
                    return false;
                }
                return true;
            } else {
                return false
            }


        });
    });

    function djs(){
        send.value = times+"秒后重试";
        send.setAttribute('disabled','disabled');
        send.style.background='#ccc';
        send.style.border='1px solid #ccc';
        times--;
        if(times <= 0){
            send.value = "发送验证码";
            send.removeAttribute('disabled');
            times = 60;
            clearInterval(timer);
        }
    }
    function yzmfn() {
        if(yzm.value == "") {
            err_msg.innerHTML = "*手机验证码不能为空";
            return false;
        }else{
            return true;
        }
    }
    yzm.onblur = yzmfn;





    function fn3() {
        var res7= phonefn()
        var res8= yzmfn()
        return res8 &&  res7;
    }

    $('#btn').on('click', function () {
        var res7= phonefn()
        var res8= yzmfn()
        if(res7 && res8){
            $.ajax({
                type: 'POST',
                url: "/home/forget/yzcode",
                data: $('form').serialize(),
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1) {
                        window.location.href="/home/forget/changeindex";
                    }else{
                        // document.getElementById('err_msg').innerHTML = "*修改失败";
                        err_msg.innerHTML = "*手机验证码错误";
                    }
                }
            });
        }

    });

</script>
</html>